<?php

namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Auth;

class PublicComposer
{
    /**
     * 用户对象的实例。
     *
     * @var UserRepository
     */
    protected $users;
    
    /**
     * 创建一个新的个人数据视图组件。
     *
     * @param  UserRepository  $users
     * @return void
     */
    public function __construct(Request $request)
    {
        // 所有依赖都会自动地被服务容器解析...
        $this->users = $request->user();
    }
    
    /**
     * 将数据绑定到视图。
     *
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        if(Auth::check()){
            $view->with(['name'=>$this->users->name,'uid'=>$this->users->id,'email'=>$this->users->email,'portrait'=>$this->users->portrait]);
        }
        
    }
}